package com.fc.happyteam.process.migrate.option;

/**
 * some is an implementation of the Option class which defines a type which is not null.
 * 
 * @param <T> the type of option
 */
public final class Some<T> implements Option<T> {
        
    private final T _value;
        
    /** 
     * initializes this with the value T.
     * @param value
     */
    public Some(T value) {
        _value = value;
    }
        
        
    /**
     * if we are unsure about the null'iness of a value this static method
     * will create either a None or a Some value based on the state.
     * 
     * @param type
     * @return a None or a Some object
     */
    public static <T> Option<T> create( T type ) {
        if ( null == type ) return new None<T>();
        return new Some<T>( type );
    }
        
    /**
     * returns the typed value.
     */
    public T get() {
        return _value;
    }

    /**
     * @see Option#isNone()
     */
    @Override
    public boolean isNone() {
        return false;
    }

    /**
     * @see com.cg.rstf.utils.option.Option#hasValue()
     */
    @Override
    public boolean hasValue() {
        return !isNone();
    }


    @Override
    public T getOr(T value) {
        return _value;
    }
}
